package com.liangliang.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.liangliang.pojo.UserInfo;
import com.liangliang.service.UserInfoService;
import com.liangliang.mapper.UserInfoMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
import java.util.Random;

/**
* @author 13172
* @description 针对表【user_info】的数据库操作Service实现
* @createDate 2024-07-20 21:02:06
*/
@Service
public class UserInfoServiceImpl extends ServiceImpl<UserInfoMapper, UserInfo>
    implements UserInfoService{

    @Autowired
    private UserInfoMapper userInfoMapper;

    @Override
    public void generateAndInsertData(int numberOfRecords) {
        List<UserInfo> userInfoList = new ArrayList<>();
        Random random = new Random();
        String[] usernames = {"john_doe", "jane_doe", "alice", "bob", "charlie", "dave", "eve", "frank"};
        String[] names = {"John Doe", "Jane Doe", "Alice", "Bob", "Charlie", "Dave", "Eve", "Frank"};
        String[] professionals = {"Engineer", "Doctor", "Teacher", "Artist", "Lawyer", "Scientist", "Manager"};
        String[] cities = {"New York", "Los Angeles", "Chicago", "Houston", "Phoenix", "Philadelphia", "San Antonio"};
        String[] sexes = {"Male", "Female"};

        for (int i = 0; i < numberOfRecords; i++) {
            UserInfo userInfo = new UserInfo();
            userInfo.setUserId((long) (i + 1));
            userInfo.setUsername(usernames[random.nextInt(usernames.length)]);
            userInfo.setName(names[random.nextInt(names.length)]);
            userInfo.setAge(18 + random.nextInt(42));
            userInfo.setProfessional(professionals[random.nextInt(professionals.length)]);
            userInfo.setCity(cities[random.nextInt(cities.length)]);
            userInfo.setSex(sexes[random.nextInt(sexes.length)]);
            userInfoList.add(userInfo);
        }

        userInfoMapper.insertBatch(userInfoList);
    }
}




